package org.datascooter.generator;

import org.datascooter.inface.IDataManager;

public class DSCounter {

	private String id;
	private String name = IdManager.DS_GLOBAL;
	private Long value = 1L;
	private long used = 0;
	private long canUsed = 1000L;
	private transient IDataManager dataManager;

	public DSCounter() {
	}

	public DSCounter(String name, IDataManager dataManager) {
		this.name = name;
		this.dataManager = dataManager;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Long getValue() {
		return value;
	}

	public void reborn() {
		this.value += canUsed;
		dataManager.update(this);
	}

	public void setValue(Long value) {
		this.value = value;
	}

	public long use() {
		used = used + 1;
		if (used >= canUsed) {
			used = 0;
			dataManager.update(this);
		}
		value = value + 1;
		return value;
	}

	public long getCanUsed() {
		return canUsed;
	}

	public void setCanUsed(long canUsed) {
		this.canUsed = canUsed;
	}

	public void setDataManager(IDataManager dataManager) {
		this.dataManager = dataManager;
		value += canUsed;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
}
